package 力扣日常刷题.木22二月.第13天219;


/**
 * @author 帅小伙
 * @date 2022/2/19
 * @description
 */
public class Demo95字符串相加 {

    public String addStrings(String num1, String num2) {
        int i = num1.length() - 1, j = num2.length() - 1, add = 0;
        StringBuffer sb = new StringBuffer();
        while (i >= 0 || j >= 0 || add != 0) {
            int x = i >= 0 ? num1.charAt(i) - '0' : 0;
            int y = j >= 0 ? num1.charAt(i) - '0' : 0;
            int res = x + y + add;
            sb.append(res % 10);
            add = res / 10;
            i --;
            j --;
        }
        return sb.reverse().toString();
    }


}
